package com.yun.zhong.fu.usercenter.controller;

import com.yun.zhong.fu.usercenter.dto.message.UserAddBonusMsgDTO;
import com.yun.zhong.fu.usercenter.dto.user.UserBonusDto;
import com.yun.zhong.fu.usercenter.entity.User;
import com.yun.zhong.fu.usercenter.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author RenPu
 * @Date 2021/1/6 14:21
 * @Version 1.0
 * @Description: 用户兑换积分记录
 **/

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class BonusController {

    private final UserService userService;

    @PutMapping("/add-bonus")
    public User addBonus(@RequestBody UserBonusDto userBonusDto) {
        Integer userId = userBonusDto.getUserId();
        this.userService.addBonus(UserAddBonusMsgDTO.builder()
                .bounus(userBonusDto.getBonus())
                .userId(userId)
                .description("兑换分享...")
                .event("BUY")
                .build());
        return this.userService.findById(userId);
    }



}
